package com.yoyo.series.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "image.db";
    private static final int DATABASE_VERSION = 2;

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, 2);
    }

    public DBHelper(Context context, String name, CursorFactory cursorfactory, int version) {
        super(context, name, cursorfactory, version);
    }

    private void createTable(SQLiteDatabase sqlitedatabase) {
        sqlitedatabase.execSQL("DROP TABLE IF EXISTS module");
        sqlitedatabase.execSQL("DROP TABLE IF EXISTS image");
        sqlitedatabase.execSQL("DROP TABLE IF EXISTS collection");
        sqlitedatabase
                .execSQL("CREATE TABLE if not EXISTS collection (categroyId INTEGER PRIMARY KEY NOT NULL,groupId INTEGER,  description TEXT, iconUrl VARCHAR, timestamp INTEGER, count INTEGER, isFav INTEGER DEFAULT 0)");
        sqlitedatabase
                .execSQL("CREATE TABLE if not EXISTS image (imageId INTEGER PRIMARY KEY NOT NULL,groupId INTEGER, categroyId INTEGER,  description TEXT, imageUrl VARCHAR, timestamp INTEGER)");
        sqlitedatabase
                .execSQL("CREATE TABLE if not EXISTS module (groupId INTEGER PRIMARY KEY NOT NULL, moduleName VARCHAR, iconUrl VARCHAR)");
    }

    public void onCreate(SQLiteDatabase sqlitedatabase) {
        createTable(sqlitedatabase);
    }

    public void onUpgrade(SQLiteDatabase sqlitedatabase, int i, int j) {
        createTable(sqlitedatabase);
    }

}
